<?php

/**
 * Created by PhpStorm.
 * User: andy
 * Date: 16/4/9
 * Time: 12:22
 */
class Domain_LotteryUsers {
    public $db;

    public function  __construct() {
        $this->db = new Model_LotteryUsers();

    }

    function check($openid) {
        return $this->db->getbyopenid($openid);

    }

    function updatebyopenid($openid, $info) {
        return $this->db->updatebyopenid($openid, $info);

    }

    function addPeople($people) {
        return $this->db->insertUser($people);

    }

    function update($openid, $name, $tel) {
        DI()->cache->set("name:" . $openid, DI()->helper->hideStar($name));
        if ($this->check($openid)) {
//            update

            return $this->updatebyopenid($openid, [
                'name'       => $name,
                'tel'        => $tel,
                'updatetime' => DI()->helper->getTime()
            ]);
        }
        return $this->addPeople([
            'openid'     => $openid,
            'name'       => $name,
            'tel'        => $tel,
            'updatetime' => DI()->helper->getTime()
        ]);


    }


    function gettotal() {
        return $this->db->gettotal();
    }

    function gettotalByToday() {
        return $this->db->gettotalByToday();
    }

    function gettotalUser($openid) {
        return $this->db->gettotalUser($openid);
    }

    function gettotalUserByTodayy($openid) {
        return $this->db->gettotalUserByToday($openid);
    }

    function insertUser($openid) {
        $time = DI()->helper->getTime();
        $ip = DI()->helper->getClientIp();
        return $this->db->insertUser($openid, $time, $ip);
    }


//wxvk_Lottery

}